/**
 * @file        usart-stm32f4xx.h
 *
 * @brief       
 *
 * @date        Dec 1, 2012 12:05:05 PM
 *
 * @author      Ashwin Vijayakumar
 *
 * @copyright   (C) 2012 Ashwin Vijayakumar <ashwin@afflatustech.com>
 * @copyright   (C) 2012 Afflatus Techtronics <www.afflatustech.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 */

#ifndef USART_STM32F4XX_H_
#define USART_STM32F4XX_H_

/* ---- System headers ------------------------------------------------------ */
/* ---- Local headers ------------------------------------------------------- */
#include "stm32f4xx.h"

/* ---- Typedef section (lower_case_type) ----------------------------------- */

typedef USART_TypeDef           usart_port_type;

/* ---- Constants section (ALL_CAPS) ---------------------------------------- */
/* ---- Macros section (ALL_CAPS) ------------------------------------------- */
/* ---- Global variables section (lower_case) ------------------------------- */
/* ---- Function prototypes section (lower_case) ---------------------------- */
/* ---- Getter/setter method section (get/set/is_lower_case) ---------------- */

/**
 * @fn          is_usart_stm32f4xx_tdr_empty
 * @brief       Check if TX data register is empty
 *              => data has been moved to the shift register
 * @return      0 => TDR is not yet empty, return back and check again
 *              else, TDR is empty, USART HW is ready to accept another data unit
 * @warning     Do not call this function before transferring the first byte,
 *              it will always return a '0'
 */
static inline unsigned int
is_usart_stm32f4xx_tdr_empty( usart_port_type* usart_port )
{
  return( (unsigned int)(usart_port->SR & USART_SR_TXE) );
}

/**
 * @fn          is_usart_stm32f4xx_tx_complete
 * @brief       Check if data frame transmission is complete
 *              => TDR too is empty
 * @return      0 => Data frame has not yet been transmitted
 *              else, Data frame has been transmitted
 */
static inline unsigned int
is_usart_stm32f4xx_tx_complete( usart_port_type* usart_port )
{
  return( (unsigned int)(usart_port->SR & USART_SR_TC) );
}

/**
 * @fn          is_usart_stm32f4xx_rx_not_empty
 * @return      0 => Data is not received
 *              else, Received data is ready to be read
 */
static inline unsigned int
is_usart_stm32f4xx_rx_not_empty( usart_port_type* usart_port )
{
  return( (unsigned int)(usart_port->SR & USART_SR_RXNE) );
}


#endif /* USART_STM32F4XX_H_ */

/* ==== End of file ================= Copyright (C) 2012 Afflatus Techtronics */
